package com.winchain.chainbill.basic.cus.service.impl;

import com.shell.bee.persistence.service.impl.PersistentServiceImpl;
import com.winchain.chainbill.basic.cus.dao.CusRelDao;
import com.winchain.chainbill.basic.cus.po.CusRel;
import com.winchain.chainbill.basic.cus.service.CusRelService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("basCusRelService")
public class CusRelServiceImpl extends PersistentServiceImpl<CusRel> implements CusRelService {
	@Autowired
	private CusRelDao basCusRelDao;

	public List<CusRel> getTgtIdBySrcIdAndRelType(String srcId, String relType) {
		CusRel cusRel = new CusRel();
		cusRel.setSrcId(srcId);
		cusRel.setRelType(relType);
		return this.basCusRelDao.select(cusRel);
	}

	public String getSrcIdByTgtIdAndRelType(String tgtId, String relType) {
		CusRel cusRel = new CusRel();
		cusRel.setTgtId(tgtId);
		cusRel.setRelType(relType);
		cusRel = (CusRel) this.basCusRelDao.selectOne(cusRel);
		if (cusRel == null) {
			return null;
		}
		return cusRel.getSrcId();
	}

	public boolean checkCusRel(String tgtId, String srcId, String relType) {
		CusRel cusRel = new CusRel();
		cusRel.setTgtId(tgtId);
		cusRel.setRelType(relType);
		cusRel.setSrcId(srcId);
		return this.basCusRelDao.selectOne(cusRel) != null;
	}
}
